function gadget:GetInfo()
	return {
	name      = "Gadget Framework",
	desc      = "Globalize Functions",
	author    = "SkyStar",
	date      = "2010", 
	license   = "GNU GPL, v2 or later",
	layer     = -99999, --lowest go first
	enabled   = true, --loaded by default
	handler   = true, --access to handler
	}
end



if (gadgetHandler:IsSyncedCode()) then

--------------------------------------
--------------- SYNCED ---------------
--------------------------------------

local luaAIAllyID = {}
local luaAITeamID = {}
local basePos = {}
local security = math.random(1,1000000)
--------------------------------------

	function gadget:Initialize() -- Best Idea EVER!!
	local teams = Spring.GetTeamList()	
	local mapCenterX = Game.mapSizeX / 2
	local mapCenterZ = Game.mapSizeZ / 2
	-- Find the two LuaAI needed --	
		for _, teamID in ipairs(teams) do
		local teamLuaAI = Spring.GetTeamLuaAI(teamID)
			if (teamLuaAI and teamLuaAI ~= "") then
			local _,_,_,_,_,allyID = Spring.GetTeamInfo(teamID)
			luaAIAllyID[tonumber(allyID)] = teamID
			luaAITeamID[teamID] = tonumber(allyID)
			end		
		end		
	-- Global functions --
	_G.functions = {
	
	['secureNum'] = function()
	return security
	end,
	
	['getLuaAIAllies'] = function()
	return luaAIAllyID
	end,
	
	['getLuaAITeams'] = function()
	return luaAITeamID
	end,
	
	['getFacing'] = function(x,z)
	return math.abs(Game.mapSizeX/2 - x) > math.abs(Game.mapSizeZ/2 - z) and ((x>Game.mapSizeX/2) and "west" or "east") or ((z>Game.mapSizeZ/2) and "north" or "south")
	end,
	
	['createUnit'] = function(unitDef, x, y, z, facing, teamID, blocking)
	getfenv(0).AllowUnsafeChanges("USE AT YOUR OWN PERIL")
	local unitID = Spring.CreateUnit(unitDef, x, y, z, facing, teamID)
	Spring.SetUnitLineage(unitID, teamID, false)
	Spring.SetUnitBlocking(unitID, blocking)	
	getfenv(0).AllowUnsafeChanges("Turn OFF")	
	end,
		
	['destroyUnit'] = function(unitID, normal)
	getfenv(0).AllowUnsafeChanges("USE AT YOUR OWN PERIL")
	Spring.DestroyUnit(unitID, true, normal)
	getfenv(0).AllowUnsafeChanges("Turn OFF")	
	end,
	
	['isEngine'] = function(unitID)
	local unitDefName = UnitDefs[Spring.GetUnitDefID(unitID) or -1].name
	local engines = {["rook"] = true, ["queen"] = true, ["bishop"] = true, ["knight"] = true}
	return engines[unitDefName]
	end,
	
	['getUnitDef'] = function(unitID)
	return UnitDefs[Spring.GetUnitDefID(unitID) or -1]
	end,
	
	['split'] = function(str, delim, maxNb)
	-- Eliminate bad cases... --
		if string.find(str, delim) == nil then
        return { str }
		end
		if maxNb == nil or maxNb < 1 then
        maxNb = 0    -- No limit
		end
    local result = {}
    local pat = "(.-)" .. delim .. "()"
    local nb = 0
    local lastPos
		for part, pos in string.gmatch(str, pat) do
        nb = nb + 1
        result[nb] = part
        lastPos = pos
			if nb == maxNb then break end
		end
    -- Handle the last field --
		if nb ~= maxNb then
        result[nb + 1] = string.sub(str, lastPos)
		end
	return result
	end,
	
	['toBoolean'] = function(str)
	return str == 1 and true or str == 0 and false or str == "false" and false or str == "true" and true
	end,
	
	['towardsMapCenter'] = function(x,y,z,dist)
		if (x) then
		vx = mapCenterX - x
		vz = mapCenterZ - z
		x = x + vx*dist/math.abs(vx)
		z = z + vz*dist/math.abs(vz)		
		end
		return x,y,z
	end,
	
	['getDistance'] = function(px,pz,fx,fz)
	return (px-fx)^2 + (pz-fz)^2
	end,
	
	['getAllyID'] = function(teamID)
	local _,_,_,_,_,allyID = Spring.GetTeamInfo(teamID)	
	return allyID
	end,
	
	}
	
	Gfunction = _G.functions
	end	
	
	function gadget:RecvLuaMsg(msg, playerID) -- Recieve commands from unsynced ()
		if string.find(msg,"Gfunction:") then
		local txt = msg:gsub("Gfunction:","")
		local params = Gfunction.split(txt,',')
		-- Create an AI Turret --	
			if(params[1] == 'createTurret' and tonumber(params[6]) == security) then
			local allyID = tonumber(params[5]	)
			local x,y,z = params[2],params[3],params[4]
			local facing = Gfunction.getFacing(tonumber(x),tonumber(z))
			Gfunction.createUnit("turreta", x, y, z, facing, luaAIAllyID[allyID], true)					
			end
		end
	end
	
	
else
	
---------------------------------------
-------------- UN-SYNCED --------------
---------------------------------------



end

